#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using UnityEngine;

namespace GridSystem
{
    /// <summary>
    /// 用于传递放置预览信息的事件参数。
    /// </summary>
    public class PlacementPreviewEventArgs : EventArgs
    {
        public readonly GridSurface Surface;
        public readonly List<Vector2Int> Footprint;
        public readonly bool IsValid;
        public readonly PlaceableObject Placeable;

        public PlacementPreviewEventArgs(GridSurface surface, List<Vector2Int> footprint, bool isValid, PlaceableObject placeable)
        {
            Surface = surface;
            Footprint = footprint;
            IsValid = isValid;
            Placeable = placeable;
        }
    }

    /// <summary>
    /// 【核心桥梁】提供一个运行时的静态事件中心，用于解耦运行时逻辑与编辑器可视化逻辑。
    /// </summary>
    public static class GridSystemEvents
    {
        /// <summary>
        /// 当放置预览状态更新时触发。
        /// PlaceController (运行时) -> GridSystemVisualization (编辑器)
        /// </summary>
        public static event Action<PlacementPreviewEventArgs> OnPlacementPreview;

        // --- 运行时实例登记处 ---
        /// <summary>
        /// 一个可靠的列表，用于在运行时跟踪所有活动的GridSurface实例。
        /// </summary>
        public static readonly List<GridSurface> ActiveSurfaces = new List<GridSurface>();

        /// <summary>
        /// 【运行时调用】触发预览更新事件。
        /// </summary>
        public static void RaisePlacementPreview(GridSurface surface, List<Vector2Int> footprint, bool isValid, PlaceableObject placeable)
        {
            OnPlacementPreview?.Invoke(new PlacementPreviewEventArgs(surface, footprint, isValid, placeable));
        }

        /// <summary>
        /// 【运行时调用】触发清除预览的事件。
        /// </summary>
        public static void RaiseClearPlacementPreview()
        {
            // 传递null参数来表示清除
            OnPlacementPreview?.Invoke(null);
        }
    }
}
#endif